package com.bh.web.controller.wms;

import com.bh.common.annotation.Log;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.core.page.TableDataInfo;
import com.bh.common.enums.BusinessType;
import com.bh.common.utils.poi.ExcelUtil;
import com.bh.wms.domain.WmsSku;
import com.bh.wms.service.IWmsSkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * SKU管理接口
 *
 * @author GPT
 */
@Api(tags = "WMS SKU管理")
@RestController
@RequestMapping("/wms/sku")
public class WmsSkuController extends BaseController {

    @Autowired
    private IWmsSkuService skuService;

    @ApiOperation("分页查询SKU")
    @PreAuthorize("@ss.hasPermi('wms:sku:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsSku query) {
        startPage();
        List<WmsSku> list = skuService.selectWmsSkuList(query);
        return getDataTable(list);
    }

    @ApiOperation("导出SKU")
    @PreAuthorize("@ss.hasPermi('wms:sku:export')")
    @Log(title = "WMS SKU", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsSku query) {
        List<WmsSku> list = skuService.selectWmsSkuList(query);
        ExcelUtil<WmsSku> util = new ExcelUtil<>(WmsSku.class);
        util.exportExcel(response, list, "SKU数据");
    }

    @ApiOperation("获取SKU详情")
    @PreAuthorize("@ss.hasPermi('wms:sku:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(skuService.selectWmsSkuById(id));
    }

    @ApiOperation("新增SKU")
    @PreAuthorize("@ss.hasPermi('wms:sku:add')")
    @Log(title = "WMS SKU", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsSku entity) {
        return toAjax(skuService.insertWmsSku(entity));
    }

    @ApiOperation("修改SKU")
    @PreAuthorize("@ss.hasPermi('wms:sku:edit')")
    @Log(title = "WMS SKU", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsSku entity) {
        return toAjax(skuService.updateWmsSku(entity));
    }

    @ApiOperation("删除SKU")
    @PreAuthorize("@ss.hasPermi('wms:sku:remove')")
    @Log(title = "WMS SKU", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(skuService.deleteWmsSkuByIds(ids));
    }
}

